package com.sbl.ui;

import com.sbl.service.IAccountService;
import com.sbl.service.impl.AccountServiceImpl;
import com.sun.java.accessibility.util.AccessibilityListenerList;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *  模拟表现层
 *      1.Bean的三种创建方式
 *      2.Bean 对象的生命周期、单例及多例
 */
public class Client2 {
    public static void main(String[] args) {
        //这句话执行完，扫描了xml，对象都创建出来，存入容器了
        ClassPathXmlApplicationContext applicationContext =  new ClassPathXmlApplicationContext("bean2.xml");
//        IAccountService iAccountService = applicationContext.getBean("accountService", AccountServiceImpl.class);
//        //普通工厂方式创建对象，用于三方jar提供获取实例类，我们无法获取到构造方法
//        IAccountService iAccountService2 = applicationContext.getBean("accountService2", AccountServiceImpl.class);
//        //通过 静态工厂创建对象，也是用于jar包中提供的静态获取实例类
//        IAccountService iAccountService3 = applicationContext.getBean("accountService3", AccountServiceImpl.class);
//
//        //下面校验 prototype 属性，创建多例 对象
//        IAccountService iAccountServiceProto = applicationContext.getBean("accountServiceProto", AccountServiceImpl.class);
//        IAccountService iAccountServiceProto2 = applicationContext.getBean("accountServiceProto", AccountServiceImpl.class);
//        System.out.println(iAccountServiceProto);
//        System.out.println(iAccountServiceProto2);

        //生命周期
        AccountServiceImpl accountService = applicationContext.getBean("accountServiceLifecycle", AccountServiceImpl.class);
        System.out.println(accountService);
//        accountService.destroy();
//        System.out.println(accountService);
        applicationContext.close();
        System.out.println(accountService);

    }
}
